const app =getApp();
Page({
  //share part 
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '火花画布',
      path: '/pages/canvas_index/index?invitor='+app.globalData.userInfo.nickName+'&canvasName='+this.data.canvasName,
      success: function (res) {
        console.log("转发成功："+res)
      },
      fail: function (res) {
       console.log(res); 
      }
    }
  },
  chooseCanvas:function(e){
  var canvasName = this.data.canvasList[e.currentTarget.dataset.index];
  this.setData({canvasName:canvasName});
 
  },
  /**
   * 页面的初始数据
   */
  data: {
    canvasList:[],
    canvasName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var nickName = app.globalData.userInfo.nickName;
    console.log("toshare"+nickName);
    wx.request({
      url: getApp().globalData.my_server+'/canvas/requestList',
      method: 'POST',
      data:{
        nickName:nickName
      },
      header:{
        "Content-Type":"application/x-www-form-urlencoded"
      },
      success:function(res){
        console.log(JSON.stringify(res.data));
        console.log(res.data.length);
        var temp =[];
        for(var o in res.data){
          
          temp.push((res.data[o].canvasName))
        }
        console.log(temp);
        that.setData({canvasList:temp});
        console.log(that.data.canvasList);
      }
    })
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})